module Aio::Text

  # 将提取的关键信息附带的增加所在上下文以及行数
  class MatchStringInfo < Struct.new(:var, :content, :line)

    # 存放比较后的不同值，也是 MachStringInfo 类
    attr_accessor :compare_val

    def initialize(var, content, line)
      super(
        var,
        content,
        line
      )
    end

    def inspect
      var.to_s
    end

    def to_s
     var 
    end

    # 覆盖原有的eql?
    def eql?(other_match)
      self.to_s.eql?(other_match.to_s)
    end

    # 判断和另一个class是否是同一个content
    def same_content?(other_match)
      content == other_match.content
    end

    # 判断是否和另一个值为同一行
    def same_line?(other_match)
      if same_content?
        return line == other_match.line
      end
      return false
    end

    # 判断是否有compare_val值
    def compare_val?
      !@compare_val.nil?
    end

    # 差异值的文本
    def compare_content
      compare_val.content
    end

    # 差异值的行数
    def compare_line
      compare_val.line
    end

    def var;  self[:var].to_s;     end
    def content; self[:content]; end
    def line;    self[:line];    end

    def method_missing(m, *args)
      if var.respond_to?(m)
        var.send(m, *args)
      
      else
        super
      end
    end

  end
end

